import { ref } from "vue";
export const useFields = () => {
  // 保存
  const disableSave = ref(false);
  // 赋值
  const disableCopy = ref(false);
  // 提交
  const disableSubmit = ref(true);
  // 撤销
  const disableCancel = ref(true);
  // 审核
  const disableCheck = ref(true);
  // 反审核
  const disableUnCheck = ref(true);
  // 禁用
  const disableDisable = ref(true);
  // 反禁用
  const disableUnDisable = ref(true);
  // 关闭
  const disableClose = ref(false);
  // 下推
  const disablePush = ref(true);
  // 下达
  // 反下达

  const editStatus = ref(true);
  const viewStatus = ref(false);

  /** 状态判断 */
  const statusJudge = (data) => {
    // 暂存
    if (data?.dataStatus == 1) {
      disableSave.value = false;
      disableSubmit.value = false;
      disableCancel.value = true;
      disableCheck.value = true;
      disableUnCheck.value = true;
      editStatus.value = true;
      viewStatus.value = false;
      disablePush.value = true;
    }
    // 提交
    if (data?.dataStatus == 2) {
      disableSave.value = true;
      disableSubmit.value = true;
      disableCancel.value = false;
      disableCheck.value = false;
      disableUnCheck.value = true;
      disableDisable.value = false;
      disableUnDisable.value = false;
      editStatus.value = false;
      viewStatus.value = true;
      disablePush.value = true;
    }
    // 已审核
    if (data?.dataStatus == 3) {
      disableSave.value = true;
      disableSubmit.value = true;
      disableCancel.value = true;
      disableCheck.value = true;
      disableUnCheck.value = false;
      disableDisable.value = false;
      disableUnDisable.value = false;
      editStatus.value = false;
      viewStatus.value = true;
      if (data?.businessStatus == 1) {
        disablePush.value = false;
      } else {
        disablePush.value = true;
      }
    }
    // 禁用
    if (data?.disableStatus == 1) {
      disableDisable.value = false;
      disableUnDisable.value = true;
    }
    // 反禁用
    if (data?.disableStatus == 2) {
      disableDisable.value = true;
      disableUnDisable.value = false;
    }
    // id不存在
    if (!data || !data?.id) {
      disableSave.value = false;
      disableCopy.value = false;
      disableSubmit.value = true;
      disableCancel.value = true;
      disableCheck.value = true;
      disableUnCheck.value = true;
      disableDisable.value = true;
      disableUnDisable.value = true;
      disableClose.value = false;
    }
  };

  return {
    disableSave,
    disableCopy,
    disableSubmit,
    disableCancel,
    disableCheck,
    disableUnCheck,
    disableDisable,
    disableUnDisable,
    disableClose,
    disablePush,
    viewStatus,
    editStatus,
    statusJudge,
  };
};
